<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var number = Math.floor(Math.random()*10);
        function guess(){
            var value = parseInt(document.getElementById("txt").value);
            if (isNaN(value)) {
                alert("不是数字");
            }else{
                if (value == number){
                    alert("猜对了")
                }else{
                    value > number ? alert("大了") : alert("小了");
                }
            }
        }
    </script>

</head>
<body>
<input type="text" id="txt" placeholder="请输入一个10以内的数">
<input type="button" value="ok" onclick="guess()">

</body>
</html>